<?php
class categoryMod extends commonMod
{
    public function __construct()
    {
        parent::__construct();
    }
    public function getList(){
        
        $cid = intval($_GET['cid']);
        //读取栏目信息
        $this->info=model('category')->info($cid);
        if (!is_array($this->info)){
            $this->error404();
        }
        //模块自动纠正
        model('category')->model_jump($this->info['mid'],'category');

        /*hook*/
        $this->plus_hook('category','index',$this->info);
        $this->info=$this->plus_hook_replace('category','index_replace',$this->info);
        /*hook end*/


        if ($this->info['type'] == 0) {
            $son_id = model('category')->getcat($this->info['cid']);
            $where = 'A.status=1 AND B.cid in (' . $son_id . ')';
        } else {
            $where = 'A.status=1 AND B.cid=' . $this->info['cid'];
        }

        $sloop=model('category')->content_list($cid,$where,40,$this->info['content_order']);
        $json = json_encode(array(
            "resultCode"=>200,
            "message"=>"查询成功！",
            "data"=>$sloop
        ),JSON_UNESCAPED_UNICODE);
        echo($json);

    }

    public function index()
    {
        $cid = intval($_GET['cid']);
        if (empty($cid)) {
            $this->error404();
        }
        
        $getinfo=in($_GET);
       unset($getinfo['_module']); 
       unset($getinfo['_action']); 
       unset($getinfo['cid']); 
       unset($getinfo['page']); 


       $this->getinfo=$getinfo;
       if(!empty($getinfo)){
       	$ext="?";
       	foreach($getinfo as $key=>$value){
       	$ext.=$key.'='.$value.'&';	
       	}
       }
       $exturl=rtrim($ext,'&');//多维筛选构造url
       
       
        //读取栏目信息
        $this->info=model('category')->info($cid);
        if (!is_array($this->info)){
            $this->error404();
        }
        //模块自动纠正
        model('category')->model_jump($this->info['mid'],'category');

        /*hook*/
        $this->plus_hook('category','index',$this->info);
        $this->info=$this->plus_hook_replace('category','index_replace',$this->info);
        /*hook end*/

//////获取扩展多属性信息
        if(!empty($this->info['expand'])){
	       $expand= model('category')->info_field($this->info['expand']);
	     
	       
	       if(!empty($expand)){
         $a=array();
         $b=array();
         $field=array();
	       	 foreach($expand as $key=>$value){
	       	 	
		      
		       	 $value['config']= htmlspecialchars($value['config']);
	           $config_expand=explode("\n",$value['config']);
	           
	           foreach($config_expand as $value2){
	           	$config_expand2=explode("|",$value2);
	           	$b[]=array($config_expand2[0]=>$config_expand2[1]);
	           	}
	           	
	           	$field[]=$value['field'];//多选的字段全集	          
	           	$a[]=array('name'=>$value['name'],
	       	 	             'field'=>$value['field'],
	       	 	             'config'=>$b
	       	 	            );
	       	 	  unset($b);
	          }
	          
	       	 }
	       	//var_dump($field);
	       	 $this->duowei=$a;
	       	
	       	foreach($getinfo as $gkey=>$gvalue){
	       		if(!in_array($gkey,$field))unset($getinfo[$gkey]); 
	       	}
	       
	       	 $extinfo=$getinfo;
	       	
	       	$this->all_field=$field;
	       	
	       }
	      
        
///// 获取扩展多选信息结束   

        //位置导航
        $this->nav=array_reverse(model('category')->nav($this->info['cid']));

        //设置分页
        $size = intval($this->info['page']); 
        if (empty($size)) {
            $listrows = 10;
        } else {
            $listrows = $size;
        }
        $model_info = model('category')->model_info($this->info['mid']);
        $url=model('category')->url_format($model_info['url_category_page'],$cid,$this->info['urlname'],$exturl);

        
        
        $limit=$this->pagelimit($url,$listrows);

        //设置栏目属性
        if ($this->info['type'] == 0) {
            $son_id = model('category')->getcat($this->info['cid']);
            $where = 'A.status=1 AND B.cid in (' . $son_id . ')';
        } else {
            $where = 'A.status=1 AND B.cid=' . $this->info['cid'];
        }

        if(!empty($extinfo)){
            //执行查询
            $this->loop=model('category')->content_list($cid,$where,$limit,$this->info['content_order'],'content',$extinfo);
            $count = model('category')->content_count($cid,$where,'content',$extinfo);
        }else{
            //执行查询
            $this->loop=model('category')->content_list($cid,$where,$limit,$this->info['content_order']);
            $count = model('category')->content_count($cid,$where);
        
        }
				
        

        //查询上级栏目信息
        $this->parent_category = model('category')->info($this->info['pid']);
        if (!$this->parent_category) {
            $this->parent_category = array(
                "cid" => "0",
                "pid" => "0",
                "mid" => "0",
                "name" => "无上级栏目");
        }

        
        //获取分页
        $this->page=$this->page($url, $count, $listrows);
        //获取上一页代码
        $this->prepage=$this->page($url, $count, $listrows,'',1);
        //获取下一页代码
        $this->nextpage=$this->page($url, $count, $listrows,'',2);
        
        $this->count=$count;
        $this->cid=$cid;
        //MEDIA信息
        $this->common=model('pageinfo')->media($this->info['name'],$this->info['keywords'],$this->info['description']);
        
        //获取顶级栏目信息
        $this->top_category = model('category')->info($this->nav[0]['cid']);
        $this->display($this->info['class_tpl']);
    }




}

?>